import { QRCodeToDataURLOptions } from 'qrcode';

export default class QrcodeUtils {

    private static instance: QrcodeUtils;
    public static getInstance() {
        if (!this.instance) {
            this.instance = new QrcodeUtils();
        }
        return this.instance;
    }

    private QrcodeUtils() {

    }

    /**
     * 生成二维码
     * @param text 内容
     * @param options 选项 详细文档  https://www.npmjs.com/package/qrcode
     */
    public make(text: string, options?: QRCodeToDataURLOptions): Promise<string> {
        return new Promise((res) => {
            import(/* webpackChunkName: "qrcode" */'qrcode').then((module) => {
                module.default.toDataURL(text, options).then(res).catch(() => { res('') })
            });
        });
    }
}
